<!DOCTYPE html>
<html>
    <head>
        <title>WebSocket Example</title>

    </head>
    <body>
        <h1>WebSocket Example</h1>
        <p>This is an example of a WebSocket connection.</p>
        <p id="message"></p>

        <script>
            if (!window.WebSocket) {
                alert("WebSocket not supported by your browser");
            } else {
                var ws = new WebSocket("ws://localhost:8080/echo");
                ws.onopen = function() {
                    console.log("WebSocket connection established");

                    var msg = "7788!";
                    ws.send(msg);
                    document.getElementById("message").innerHTML = "send:" + msg;
                };
                ws.onmessage = function(event) {
                    console.log("Received message: " + event.data);
                    document.getElementById("message").innerHTML = "recv:" + event.data;
                };
                ws.onclose = function() {
                    console.log("WebSocket connection closed");
                };
            }


        </script>

    </body>
</html>
